<?php
		session_start();
define('TEMPLATES', '../templates/');
define('JS','../js/');
define('CSS','../css/');
define('OBJETOS','../objetos/');
define('NEGOCIOS','../negocio/');
define('EXTENSION','.phtml');
function __autoload($class_name){
  require_once $class_name . '.php';
}
 
Class TransaccionTarifa {
	
	var $AdminObj;
	var $generador_xhtml;
	var $vars;
	
	function TransaccionTarifa($array_vars){
		$this->AdminObj=new AdminTarifa();
		$this->vars=$array_vars;
		$this->generador_xhtml=new GeneradorXHTML();
	}

	function transNewTarifa(){
		$Tarifa=$this->AdminObj->getNewObject("Tarifa",array(Tarifa));
		$rows_especificas=$this->generador_xhtml->generarRowsTable($this->AdminObj->getTemporadasTarifa($this->vars['id_estancia'], "especifica"),'button',false,0, "Eliminar");
		$rows_generales=$this->generador_xhtml->generarRowsTable($this->AdminObj->getTemporadasTarifa($this->vars['id_estancia'], "general"),'button',false,0, "Eliminar");
		$datos_defecto=$this->AdminObj->getTemporadasTarifa($this->vars['id_estancia'], "defecto");

		$this->generador_xhtml->mostrarTpl($Tarifa,array("tpl"=>"Tarifa"  ,"boton"=>"Continuar","accion"=>"transSetTarifa2","css"=>"Tarifa","js"=>"Tarifa", "rows_especificas"=>$rows_especificas, "rows_generales"=>$rows_generales, "datos_defecto"=>$datos_defecto));
		
	}
	
	function transSetTarifa(){
		$this->vars['id_tarifa']=$this->AdminObj->getNewID("Tarifa","id_Tarifa");
		$Tarifa=$this->AdminObj->getNewObject("Tarifa",$this->vars);
		echo($Tarifa->id_tarifa);
		$this->AdminObj->setTarifa($Tarifa);
		
		//$this->AdminObj->redireccionar("TransaccionTarifa.php");
	}
	function transSetTarifa2(){
		$this->vars['id_tarifa']=$this->AdminObj->getNewID("Tarifa","id_Tarifa");
		$this->vars['id_temporada']=$this->AdminObj->getNewID("Temporada","id_temporada");
		
		$this->AdminObj->setTarifaTemporada($this->vars);
		$this->AdminObj->redireccionar("transaccionAlta.php?a=transNewAlta&id_estancia=".$this->vars['id_estancia']);
		
	}
	
	function transGetTarifa(){
		$Tarifa=$this->AdminObj->getTarifa($this->vars['id_tarifa']);
		
		
		
		$array_elementos=array("tpl"=>"Tarifa"  ,"boton"=>"Continuar","accion"=>"transUpdateTarifa","css"=>"Tarifa","js"=>"Tarifa");
		$this->generador_xhtml->mostrarTpl($Tarifa,$array_elementos);
	}
	
	function transUpdateTarifa(){
		$Tarifa=$this->AdminObj->getNewObject("Tarifa",$this->vars);
		$this->AdminObj->updateTarifa($Tarifa);
		$this->AdminObj->redireccionar("TransaccionTarifa.php");	
	}
	
	function transDeleteTarifa(){
		$this->AdminObj->deleteTarifa($this->AdminObj->getTarifa($this->vars['id_tarifa']));
		//$this->AdminObj->redireccionar("TransaccionTarifa.php");
	}
	function transGetTarifas()
	{
		$rows=$this->generador_xhtml->generarRowsTable($this->AdminObj->getTarifas(),"checkbox",false,0);
		$this->generador_xhtml->mostrarTpl("",array("tpl"=>"Tarifastable","rows"=>$rows,"js"=>"Tarifastable.js"));
	}		
}

if($_GET){
	$vars_trans=array_slice($_GET,1);
//antes no olvidar poner una validador para que nadie pueda ejecutar las funciones
	call_user_func(array(new TransaccionTarifa($vars_trans),current($_GET)?current($_GET):"transGetTarifas"));
}
else if($_POST){
		$vars_trans=array_slice($_POST,1);
		call_user_func(array(new TransaccionTarifa($vars_trans),current($_POST)?current($_POST):"transGetTarifas"));
		}
	else	call_user_func(array(new TransaccionTarifa(array()),"transGetTarifas"));

?>